<template>
	<block>
		<List :listDatas="listDatas" @list:click="receiveCoupon">
			<template v-slot="{ item }">
				<view class="coupon">
					<view class="coupon-left">
						<view class="f-w">
							<block v-if="item.scope == '1'">
								{{item.name}}
							</block>
							<block v-else-if="item.scope == '2'">
								<view class="flex">
									<!-- <view class="profile-tenant"> -->
										<!-- <sl-image :value="item.tenantHeadimg"></sl-image> -->
									<!-- </view> -->
									{{item.tenantName}}
								</view>
							</block>
						</view>
						<view class="f-24 f-tip py-1">
							{{item.scopeDesc}}
						</view>
						<view class="f-24 f-tip p-a bottom-0">
							{{item.expireDesc}}
						</view>
					</view>
					<view class="coupon-right">
						<view class="right-block">
							<view class="block-price">
								<block v-if="item.type == '0'">
									-<Money :priceValue="item.val" :activeClass="['money-price','money-price-white']"></Money>
								</block>
								<block v-else-if="item.type == '1'">
									{{item.val}}折
								</block>
							</view>
							<view class="block-scope oneline-hide">
								{{item.limitDesc}}
							</view>
							<view class="block-receive" @click.stop="receiveCoupon(item.id)">
								领取
							</view>
						</view>
					</view>
				</view>
			</template>
		</List>
	</block>
</template>

<script>
	import CouponApi from '@/api/coupon/coupon.js';
	import Constants from '@/constants';
	import Money from '@/pages/components/money/money.vue';
	import List from '@/pages/components/list/list.vue';
	//优惠券组件（领券中心）
	//@group 业务组件
	export default {
		//
		name: 'couponReceive',
		//
		mixins: [Constants],
		//
		components: {
			List,
			Money
		},
		//
		data() {
			return {};
		},
		//
		props: {
			//优惠券集合
			listDatas: {
				type: Array,
				default () {
					return [];
				}
			}
		},
		//
		methods: {
			//领取优惠券
			receiveCoupon: async function(id) {
				console.log('id',id)
				const res = await CouponApi.get(id);
				console.log('CouponApi',res)
				this.$emit('receiveCoupon:result', res);
			}
			
		}
	};
</script>

<style lang="scss" scoped>
	.coupon {
		font-size: $uni-font-size-base;
		height: 188rpx;
		position: relative;
		display: flex;
		justify-content: space-between;

		.coupon-left {
			font-size: $uni-font-size-lg;
			flex:1;
			padding: 16rpx 38rpx;

			.profile-tenant {
				position: relative;
				width: 52rpx;
				height: 52rpx;
				margin-right: 16rpx;
			}
		}

		.coupon-right {
			display: flex;
			align-items: center;

			.right-block {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				width: 115px;
				height: 92px;
				border-radius: 8px;
				background: linear-gradient(135deg, #FFC28A 0.01%, #FF2323 100%);
				padding: 10rpx;
				.block-price {
					color: $uni-text-color-inverse;
					text-align: center;
					font-size: 40rpx;
					font-weight: 700;
					line-height: 44rpx;
					margin-top: 8rpx;
					display: flex;
				}

				.block-scope {
					color: $uni-text-color-inverse;
					text-align: center;
					font-size: 20rpx;
					line-height: 44rpx;
				}

				.block-receive {
					display: flex;
					padding: 4rpx 16rpx;
					justify-content: center;
					align-items: center;
					border-radius: 76rpx;
					border: 0.5px solid $uni-text-color-inverse;
					color: $uni-text-color-inverse;
					font-weight: 500;
					width: 140rpx;
				}
			}
		}
	}
</style>